import axios from 'axios'   ///封装了axios ---用http来代替
import { Toast } from "vant";
const http = axios.create({
    baseURL: 'http://crm.cimns.com/index.php/',
    timeout: 10000,

});

///axios  拦截器和路由拦截差不多

//拦截器前toloading框

//http.interceptors.request()
///发送前
//http.interceptors.response()
//收到后
// Add a request interceptor
http.interceptors.request.use(function (config) {
    // Do something before request is sent
    ///启动loading
    Toast.loading({
        message: "加载中...",
        forbidClick: true,
        overlay: true,
        duration: 0
    });
    // window.sessionStorage.setItem("token", res.data.data.authKey);
    //config.headers.Authoruzation = window.sessionStorage.getItem('token')

    config.headers.authKey = window.sessionStorage.getItem("token");
    config.headers.sessionId = window.sessionStorage.getItem("sessionId")
    // config.headers.=window.sessionStorage.setItem('sessionId', res.data.data.sessionId)
    return config;
}, function (error) {
    // Do something with request error
    return Promise.reject(error);
});

// Add a response interceptor
http.interceptors.response.use(function (response) {

    Toast.clear();

    return response;
}, function (error) {

    return Promise.reject(error);
});




export default http